/*
 * Copyright (c) 2016-2018 Hunan CNBOT Co., Ltd. All Rights Reserved.
 * FileName: ThreadUtil.java
 * @author: Clintonfang
 * @date: 18-12-11 下午4:07
 * @version: 1.0
 */

package com.cnbot.toolkit.threadpool;

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author wzz
 */
public final class ThreadUtil {

	private static final String TAG = ThreadUtil.class.getSimpleName();

	private static final AtomicInteger M_COUNT = new AtomicInteger(1);

	private ThreadUtil() {}

	/**
	 * ThreadFactory用于构建线程
	 *
	 * @param name   名称
	 * @param daemon 是否守护
	 * @return ThreadFactory
	 * @author Clintonfang
	 * @date 2018-12-12 06:25:21
	 */
	public static ThreadFactory threadFactory(final String name, final boolean daemon) {
		return new ThreadFactory() {
			@Override
			public Thread newThread(Runnable r) {
				Thread result = new Thread(r, name + "#" + M_COUNT.getAndIncrement());
				result.setDaemon(daemon);
				return result;
			}
		};
	}
}
